using System;
using System.Windows.Forms;
using System.Globalization;
using Transferomatic.Views;

namespace Transferomatic.ApplicationControllers
{
    public partial class Controller
    {
        #region Methods
        private void SettingsView_Show(MainView theParentView)
        {
            // Instantiate an instance
            SettingsView theView = new SettingsView();

            theView.buttonOK.Click += 
                new EventHandler(SettingsView_buttonOK_Click);
            theView.buttonCancel.Click += 
                new EventHandler(SettingsView_buttonCancel_Click);

            theView.updownConcurrentDownloads.Value =
                RegistryAgent.ConcurrentDownloads;
            theView.updownBufferSize.Value =
                RegistryAgent.BufferSize;

            // Show the form
            theView.ShowDialog(theParentView);
        }

        #region Event Handlers
        private void SettingsView_buttonOK_Click(
            object sender, 
            EventArgs e)
        {
            Application.DoEvents();

            Button theOKButton = 
                sender as Button;
            SettingsView theParentView = 
                theOKButton.FindForm() as SettingsView;

            RegistryAgent.ConcurrentDownloads = Convert.ToInt32(
                theParentView.updownConcurrentDownloads.Value,
                CultureInfo.CurrentCulture);
            RegistryAgent.BufferSize = Convert.ToInt32(
                theParentView.updownBufferSize.Value,
                CultureInfo.CurrentCulture);

            theParentView.Close();
        }

        private void SettingsView_buttonCancel_Click(
            object sender, 
            EventArgs e)
        {
            Application.DoEvents();

            Button theCancelButton = 
                sender as Button;
            SettingsView theParentView = 
                theCancelButton.FindForm() as SettingsView;

            theParentView.Close();
        }
        #endregion
        #endregion
    }
}
